home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / Iterator.h < prev    next >
C/C++ Source or Header  |  1990-05-19  |  2KB  |  67 lines

  1. #ifndef    ITERATOR_H
  2. #define    ITERATOR_H
  3.  
  4. /*$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/Iterator.h,v 3.0 90/05/20 00:19:56 kgorlen Rel $*/
  5.  
  6. /* Iterator.h -- Declarations for Collection Iterators
  7.  
  8.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  9.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  10.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  11.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  12.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  13.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  14.  
  15. Author:
  16.     K. E. Gorlen
  17.     Computer Systems Laboratory, DCRT
  18.     National Institutes of Health
  19.     Bethesda, MD 20892
  20.     December, 1987
  21.  
  22. $Log:    Iterator.h,v $
  23.  * Revision 3.0  90/05/20  00:19:56  kgorlen
  24.  * Release for 1st edition.
  25.  * 
  26. */
  27.  
  28. #include "Object.h"
  29.  
  30. class Collection;
  31.  
  32. class Iterator: public VIRTUAL Object {
  33.     DECLARE_MEMBERS(Iterator);
  34.     const Collection* cltn;    // Collection being iterated over
  35. public:
  36.     int index;        // index of next Object
  37.     Object*    ptr;        // pointer to current Object or NULL
  38.     unsigned num;        // object number, used by Bags
  39.     Object*    state;        // additional state, e.g., a Stack
  40. protected:        // storer() functions for object I/O
  41.     virtual void storer(OIOofd&) const;
  42.     virtual void storer(OIOout&) const;
  43. public:
  44.     Iterator(const Collection&);
  45.     ~Iterator();
  46.     void reset();            // reset to beginning of Collection
  47.     Object*    operator()() const { return ptr; }    // return current object pointer
  48.     Object* operator++();        // advance to next object in Collection
  49.     const Collection* collection() const    { return cltn; }
  50.     bool operator==(const Iterator&) const;
  51.     bool operator!=(const Iterator& a) const { return !(*this==a); }
  52.     virtual void deepenShallowCopy();    // copy with cltn->deepCopy()
  53.     virtual void dumpOn(ostream& strm =cerr) const;
  54.     virtual unsigned hash() const;
  55.     virtual bool isEqual(const Object&) const;
  56.     virtual void printOn(ostream& strm =cout) const;
  57.     virtual const Class* species() const;
  58. private:                // shouldNotImplement()
  59.     virtual    int compare(const Object&) const;
  60. };
  61.  
  62. #define DO(cltn,cls,arg)\
  63. { cls* arg; Iterator DO_pos(cltn); while (arg = cls::castdown(DO_pos++)) {
  64. #define OD }}
  65.  
  66. #endif
  67.